package cn.fl.spl.service.impl;

import cmm.mid.core.framework.page.Pager;
import cn.cmm.base.framework.constant.BaseExceptionConstant;
import cn.cmm.base.framework.exception.BaseException;
import cn.cmm.base.framework.logger.eum.LogExceptionEnum;
import cn.cmm.base.framework.logger.eum.LogOperEnum;
import cn.cmm.base.framework.utils.BaseLogUtils;
import cn.cmm.base.framework.utils.CollectionUtils;
import cn.cmm.base.framework.utils.StringUtils;
import cn.fl.framework.base.context.CurrentThreadContext;
import cn.fl.spl.service.ISplRelOpLogService;
import cn.fl.spl.transform.SplRelOpLogVOTransform;
import cn.fl.spl.vo.SplRelOpLogVO;
import fl.constant.facade.framework.constant.BusinessIdConstant;
import fl.spl.facade.framework.constant.SplSystemConstant;
import fl.spl.facade.store.api.ISplRelOpLogApiService;
import fl.spl.facade.store.condition.SplRelOpLogQC;
import fl.spl.facade.store.dto.SplRelOpLogDTO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;


/**
 * @Description: 供应商相关操作日志记录表 客户端服务层接口实现
 * @Description: 业务层方法名称前缀：新增：add* 删除：remove* 修改：modify* 查询对象：select* get* 批量：batch* 查询集合：search*
 */
@Service
public class SplRelOpLogServiceImpl implements ISplRelOpLogService {

	/**
	 * 自定义 API 自行注入需要的API服务
	 */
	@Autowired
	private ISplRelOpLogApiService splRelOpLogApiService;

	@Override
	public SplRelOpLogVO selectById(Long id) throws BaseException{
		if(StringUtils.isEmpty(id)){
			BaseLogUtils.newWebLogger("主键参数为空").setLogOperType(LogOperEnum.REQ)
					.setSysCd(CurrentThreadContext.getCurrentSysCd())
					.setChannelCd(SplSystemConstant.FL_WEB_CHL_CD)
					.setBussinessId(BusinessIdConstant.LOG_SPL_MANAGER_CD)
					.setWarning(false)
					.warn(LogExceptionEnum.COMMON_CODE_0002);
			throw new BaseException(BaseExceptionConstant.COMMON_0001, "获取对象主键不能为空!");
		}
		//TODO 业务逻辑
		SplRelOpLogDTO dto = this.splRelOpLogApiService.selectSplRelOpLogDTOById(id);
		return SplRelOpLogVOTransform.toVO(dto);
	}

	@Override
	public Long add(SplRelOpLogVO entity) throws BaseException{
		if(null == entity){
			BaseLogUtils.newWebLogger("新增对象不存在").setLogOperType(LogOperEnum.REQ)
					.setSysCd(CurrentThreadContext.getCurrentSysCd())
					.setChannelCd(SplSystemConstant.FL_WEB_CHL_CD)
					.setBussinessId(BusinessIdConstant.LOG_SPL_MANAGER_CD)
					.setWarning(false)
					.warn(LogExceptionEnum.COMMON_CODE_0002);
			throw new BaseException(BaseExceptionConstant.COMMON_0001,"新增对象不存在!");
		};
		return this.splRelOpLogApiService.addSplRelOpLogDTO(SplRelOpLogVOTransform.toDTO(entity));
		//TODO 业务逻辑
	}

	@Override
	public boolean batchAdd(List<SplRelOpLogVO> splRelOpLogVOS) throws BaseException {
		if(CollectionUtils.isEmpty(splRelOpLogVOS)){
			BaseLogUtils.newWebLogger("批量新增属性信息,参数为空").setLogOperType(LogOperEnum.REQ)
					.setSysCd(CurrentThreadContext.getCurrentSysCd())
					.setChannelCd(SplSystemConstant.FL_WEB_CHL_CD)
					.setBussinessId(BusinessIdConstant.LOG_SPL_MANAGER_CD)
					.setWarning(false)
					.warn(LogExceptionEnum.COMMON_CODE_0002);
			throw new BaseException(BaseExceptionConstant.COMMON_0001, "批量新增属性信息，参数为空！");
		}
		return this.splRelOpLogApiService.batchAddSplRelOpLogDTO(SplRelOpLogVOTransform.toDTOList(splRelOpLogVOS));
	}

	@Override
	public boolean removeById(Long id) throws BaseException{
		if(StringUtils.isEmpty(id)){
			BaseLogUtils.newWebLogger("删除对象主键不能为空").setLogOperType(LogOperEnum.REQ)
					.setSysCd(CurrentThreadContext.getCurrentSysCd())
					.setChannelCd(SplSystemConstant.FL_WEB_CHL_CD)
					.setBussinessId(BusinessIdConstant.LOG_SPL_MANAGER_CD)
					.setWarning(false)
					.warn(LogExceptionEnum.COMMON_CODE_0002);
			throw new BaseException(BaseExceptionConstant.COMMON_0001,"删除对象主键不能为空!");
		};
		return this.splRelOpLogApiService.removeSplRelOpLogDTOById(id);
		//TODO 业务逻辑
		//return false;
	}
	
	/**
     * 删除
     * @param ids
     * @return
     */
	@Override
    public boolean removeByIds(List<Long> ids)throws BaseException{
		if(CollectionUtils.isEmpty(ids)){
			throw new BaseException(BaseExceptionConstant.COMMON_0001,"删除对象主键不能为空!");
		};
		return false;
    }

	@Override
	public boolean modify(SplRelOpLogVO entity) throws BaseException{
		if(null == entity){
			BaseLogUtils.newWebLogger("修改对象不能为空").setLogOperType(LogOperEnum.REQ)
					.setSysCd(CurrentThreadContext.getCurrentSysCd())
					.setChannelCd(SplSystemConstant.FL_WEB_CHL_CD)
					.setBussinessId(BusinessIdConstant.LOG_SPL_MANAGER_CD)
					.setWarning(false)
					.warn(LogExceptionEnum.COMMON_CODE_0002);
			throw new BaseException(BaseExceptionConstant.COMMON_0001,"修改对象不能为空!");
		};
		return this.splRelOpLogApiService.modifySplRelOpLogDTO(SplRelOpLogVOTransform.toDTO(entity));
	}

	@Override
	public Pager searchListPage(Pager page) throws BaseException{
		if(null == page){
			page = new Pager(); 
		}
		page = this.splRelOpLogApiService.searchSplRelOpLogListPage(page);
		if(CollectionUtils.isNotEmpty(page.getResultList())){
			List<SplRelOpLogVO> list = SplRelOpLogVOTransform.toVOList((List<SplRelOpLogDTO>) page.getResultList());
			page.setResultList(list);
		}
		return page;
	}
	
	@Override
	public List<SplRelOpLogDTO> searchList(SplRelOpLogQC qc) throws BaseException{
		if(null == qc){
			BaseLogUtils.newWebLogger("查询条件不存在").setLogOperType(LogOperEnum.REQ)
					.setSysCd(CurrentThreadContext.getCurrentSysCd())
					.setChannelCd(SplSystemConstant.FL_WEB_CHL_CD)
					.setBussinessId(BusinessIdConstant.LOG_SPL_MANAGER_CD)
					.setWarning(false)
					.warn(LogExceptionEnum.COMMON_CODE_0002);
			return null ;
	    }
		return this.splRelOpLogApiService.searchSplRelOpLogList(qc);
	}
}
